----------------------------------------------------------------
-- Global Variables
----------------------------------------------------------------

EA_Window_Inspection = {}
EA_Window_Inspection.version = 2.01


-- Constant Strings
EA_Window_Inspection.TOOLTIP_TROPHY_NEXT_LOC = GetString( StringTables.Default.TOOLTIP_TROPHY_NEXT_LOC )
EA_Window_Inspection.TOOLTIP_TROPHY_PREV_LOC = GetString( StringTables.Default.TOOLTIP_TROPHY_PREV_LOC )
EA_Window_Inspection.TOOLTIP_TROPHY_NO_AVAILABLE_LOC = GetString( StringTables.Default.TOOLTIP_TROPHY_NO_AVAILABLE_LOC )
EA_Window_Inspection.TOOLTIP_TROPHY_INVALID_LOC = GetString( StringTables.Default.TOOLTIP_TROPHY_INVALID_LOC )

-- trophy Constants
EA_Window_Inspection.NUM_TROPHY_SLOTS = GameData.Player.c_NUM_TROPHIES
EA_Window_Inspection.NORMAL_TINT = {R=255, G=255, B=255}
EA_Window_Inspection.EQUIPMENT_EMPTY_TINT = {R=204, G=168, B=144}
EA_Window_Inspection.TROPHY_EMPTY_TINT = {R=170, G=140, B=120}
EA_Window_Inspection.TROPHY_INVALID_LOC_TINT = Tooltips.COLOR_WARNING 
EA_Window_Inspection.INVALID_TROPHY_POSITION = 0

-- prevent some invalid initialization
EA_Window_Inspection.initializationComplete = false

EA_Window_Inspection.equipmentData = {}
EA_Window_Inspection.bragData = {}
EA_Window_Inspection.trophyData = {}
EA_Window_Inspection.trophyLocData = {} -- locations where trophies can be attached to

-- trophy variables
EA_Window_Inspection.currentlySelectedTrophyPosition = EA_Window_Inspection.INVALID_TROPHY_POSITION
EA_Window_Inspection.trophyDragStarted = false


-- EquipmentSlotInfo provides default icons and strings when for when no armor is equipped for that slot
EA_Window_Inspection.NUM_EQUIPMENT_SLOTS = 20

EA_Window_Inspection.EquipmentSlotInfo = {  }     
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.RIGHT_HAND]   =  { name=GetString( StringTables.Default.LABEL_RIGHT_HAND ),   iconNum=6}
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.LEFT_HAND]    =  { name=GetString( StringTables.Default.LABEL_LEFT_HAND ),    iconNum=7 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.RANGED]       =  { name=GetString( StringTables.Default.LABEL_RANGED_SLOT ),  iconNum=8 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.BODY]         =  { name=GetString( StringTables.Default.LABEL_BODY ),         iconNum=9}
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.GLOVES]       =  { name=GetString( StringTables.Default.LABEL_GLOVES ),       iconNum=10 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.BOOTS]        =  { name=GetString( StringTables.Default.LABEL_BOOTS ),        iconNum=11 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.HELM]         =  { name=GetString( StringTables.Default.LABEL_HELM ),         iconNum=12 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.SHOULDERS]    =  { name=GetString( StringTables.Default.LABEL_SHOULDERS ),    iconNum=13 }
-- No longer used, the pockets took their place
--EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.SHIRT]        =  { name=GetString( StringTables.Default.LABEL_SHIRT ),        iconNum=14 }
--EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.PANTS]        =  { name=GetString( StringTables.Default.LABEL_PANTS ),        iconNum=15 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.POCKET1]		=  { name=GetString( StringTables.Default.LABEL_POCKET ),   iconNum=36 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.POCKET2]		=  { name=GetString( StringTables.Default.LABEL_POCKET ),   iconNum=36 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.BACK]         =  { name=GetString( StringTables.Default.LABEL_BACK ),         iconNum=16 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.BELT]         =  { name=GetString( StringTables.Default.LABEL_BELT ),         iconNum=17 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.BANNER]       =  { name=GetString( StringTables.Default.LABEL_BANNER ),       iconNum=18 }
-- No longer used, mount may or may not take this place
--EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.TABARD]       =  { name=GetString( StringTables.Default.LABEL_TABARD ),       iconNum=19 }
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.ACCESSORY1]   =  { name=GetString( StringTables.Default.LABEL_ACCESSORY1 ),   iconNum=20 } 
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.ACCESSORY2]   =  { name=GetString( StringTables.Default.LABEL_ACCESSORY2 ),   iconNum=20 } 
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.ACCESSORY3]   =  { name=GetString( StringTables.Default.LABEL_ACCESSORY3 ),   iconNum=20 } 
EA_Window_Inspection.EquipmentSlotInfo[GameData.EquipSlots.ACCESSORY4]   =  { name=GetString( StringTables.Default.LABEL_ACCESSORY4 ),   iconNum=20 }
-- EquipmentSlotInfo for trophies is set programatically in  EA_Window_Inspection.UnlockTrophies()

-- Icon info for the stats icons
EA_Window_Inspection.StatIconInfo = {  }
-- Stats selections
EA_Window_Inspection.StatIconInfo[GameData.Stats.STRENGTH]   =  { iconNum=100 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.TOUGHNESS]   =  { iconNum=103 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.WOUNDS]   =  { iconNum=104 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.INITIATIVE]   =  { iconNum=105 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.WEAPONSKILL]   =  { iconNum=106 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.BALLISTICSKILL]   =  { iconNum=107 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.INTELLIGENCE]   =  { iconNum=108 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.WILLPOWER]   =  { iconNum=102 }
-- Offense selections
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_MAIN_HAND]   =  { iconNum=159 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_OFF_HAND]   =  { iconNum=158 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_ARMOR_PENETRATION]   =  { iconNum=166 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_RANGED]   =  { iconNum=157 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_SPELL_BONUS]   =  { iconNum=156 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_HEALING_BONUS]   =  { iconNum=161 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_DAMAGE_CRIT_PERCENT]   =  { iconNum=163 }
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_HEAL_CRIT_PERCENT]   =  { iconNum=160 }
-- Defense selections
EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_ARMOR]   =  { iconNum=121 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.CORPOREALRESIST]   =  { iconNum=164 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.SPIRITRESIST]   =  { iconNum=155 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.ELEMENTALRESIST]   =  { iconNum=162 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.BLOCKSKILL]   =  { iconNum=165 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.PARRYSKILL]   =  { iconNum=110 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.EVADESKILL]   =  { iconNum=111 }
EA_Window_Inspection.StatIconInfo[GameData.Stats.DISRUPTSKILL]   =  { iconNum=112 }

-- stat data
EA_Window_Inspection.STAT_ICON_BASE_ID = 100

EA_Window_Inspection.TOOLTIP_ANCHOR = { Point = "topright",  RelativeTo = "EA_Window_Inspection", RelativePoint = "topleft",  XOffset=5, YOffset=165 }

EA_Window_Inspection.FIRST_AVAILABLE_INVENTORY_SLOT = 561

EA_Window_Inspection.currentStatSelection = 1
EA_Window_Inspection.previousStatSelection = 0
EA_Window_Inspection.currentTitleSelection = 0
EA_Window_Inspection.hideHelm = false
EA_Window_Inspection.hideCloak = false


-- load commonly used trophy icons
--
--		<Icon id="00037" texture="Icons/Ge_Trophy.dds" name="   					                                	"/>
--		<Icon id="00038" texture="Icons/ovl_noValidSlot.dds" name="   					                                	"/>
--		<Icon id="00039" texture="Icons/ovl_Lock.dds" name="   					                                	"/>
--		<Icon id="00040" texture="Icons/ovl_noArmor.dds" name="   					                                	"/>

local iconTexture, iconX, iconY = GetIconData( 37 )
EA_Window_Inspection.TROPHY_EMPTY_ICON = {texture=iconTexture, x=iconX, y=iconY }

iconTexture, iconX, iconY = GetIconData( 38 )
EA_Window_Inspection.TROPHY_INVALID_ATTACHMENT_POINT_ICON = {texture=iconTexture, x=iconX, y=iconY }

iconTexture, iconX, iconY = GetIconData( 39 )
EA_Window_Inspection.TROPHY_LOCKED_ICON = {texture=iconTexture, x=iconX, y=iconY }

iconTexture, iconX, iconY = GetIconData( 40 )
EA_Window_Inspection.TROPHY_NO_ATTACHMENT_POINT_ICON = {texture=iconTexture, x=iconX, y=iconY }

EA_Window_Inspection.MODE_NORMAL = 1
EA_Window_Inspection.MODE_BRAGS  = 2
EA_Window_Inspection.mode = EA_Window_Inspection.MODE_NORMAL


----------------------------------------------------------------
-- Local Variables
----------------------------------------------------------------

EA_Window_Inspection.dropPending = false

----------------------------------------------------------------
-- EA_Window_Inspection Functions
----------------------------------------------------------------

-- OnInitialize Handler
function EA_Window_Inspection.Initialize()
    
    --LabelSetText( "EA_Window_InspectionTitleBarText",  GetString( StringTables.Default.LABEL_CHARACTER ) )
    --LabelSetText( "EA_Window_InspectionTitleBarText", GameData.Player.name )
        
    LabelSetText( "EA_Window_InspectionContentsImageNameLabel", TargetInfo:UnitName("selffriendlytarget") )
    LabelSetText( "EA_Window_InspectionBragsHeader", GetStringFormat( StringTables.Default.LABEL_PLAYERS_BRAGS_HEADER, {TargetInfo:UnitName("selffriendlytarget")} ) )

    --EA_Window_Inspection.UpdateTitleLabel()
     
    WindowRegisterEventHandler( "EA_Window_Inspection", SystemData.Events.SOCIAL_INSPECTION_UPDATED, "EA_Window_Inspection.Show")
    
--    WindowSetTintColor("EA_Window_InspectionLine1", 92, 69, 53 )
--    WindowSetTintColor("EA_Window_InspectionLine2", 92, 69, 53 )
    
--    LabelSetText( "EA_Window_InspectionArmorLabel", GetString( StringTables.Default.LABEL_ARMOR ) )
--    LabelSetText( "EA_Window_InspectionDPSLabel", GetString( StringTables.Default.LABEL_DAMAGE ) )
--    LabelSetText( "EA_Window_InspectionHPLabel", GetString( StringTables.Default.LABEL_HIT_POINTS ) )
    
--    LabelSetText( "EA_Window_InspectionStatsLabel", GetString( StringTables.Default.LABEL_STATS ) )
--    LabelSetText( "EA_Window_InspectionResistsLabel", GetString( StringTables.Default.LABEL_RESISTS )  )
    
    for stat = 1, GameData.Stats.COUNT do
    
--        if( StatInfo[stat].skip ~= true ) then          
--            local texture, x, y = GetIconData( EA_Window_Inspection.STAT_ICON_BASE_ID + stat - 1 )
--            DynamicImageSetTexture( "Stat"..stat.."Icon", texture, x, y )   
--            LabelSetText( "Stat"..stat.."Name", StatInfo[stat].name )
--            LabelSetText( "Stat"..stat.."Value", L"XXX"  )
--        end    

    end
    
    -- Hide the unused stats
--    WindowSetShowing( "Stat10", false )
--    WindowSetShowing( "Stat11", false )
--    WindowSetShowing( "Stat12", false )
--    WindowSetShowing( "Stat13", false )    

    EA_Window_Inspection.UpdateStats()
    EA_Window_Inspection.UpdateHitPoints()
    EA_Window_Inspection.UpdateCareerRank()

    EA_Window_Inspection.hideTrophyLocArrows()

    EA_Window_Inspection.UpdateStatCombobox()

--	ButtonSetCheckButtonFlag("EA_Window_InspectionEquipmentHideHelm", true )
--	ButtonSetPressedFlag("EA_Window_InspectionEquipmentHideHelm", true )
--	WindowSetShowing("EA_Window_InspectionEquipmentHideHelm", false)
--	ButtonSetCheckButtonFlag("EA_Window_InspectionEquipmentHideCloak", true )
--	ButtonSetPressedFlag("EA_Window_InspectionEquipmentHideCloak", true )
--	WindowSetShowing("EA_Window_InspectionEquipmentHideCloak", false)

    ButtonSetText( "EA_Window_InspectionTabsCharTab", GetString( StringTables.Default.LABEL_CHARACTER ) )
    ButtonSetText( "EA_Window_InspectionTabsBragsTab", GetString( StringTables.Default.LABEL_BRAGS ) )
    
    EA_Window_Inspection.UpdateMode( EA_Window_Inspection.MODE_NORMAL )
end

function EA_Window_Inspection.UpdateMode( mode )
    if( mode )
    then
        local inNormalMode = true
        EA_Window_Inspection.mode = mode
        
        if( mode == EA_Window_Inspection.MODE_BRAGS )
        then
            inNormalMode = false
        end
        
        WindowSetShowing( "EA_Window_InspectionTabs", true )
        
        WindowSetShowing( "EA_Window_InspectionContents", inNormalMode )
        WindowSetShowing( "EA_Window_InspectionBrags", not inNormalMode )
        
        ButtonSetPressedFlag( "EA_Window_InspectionTabsCharTab", inNormalMode )
        ButtonSetStayDownFlag( "EA_Window_InspectionTabsCharTab", inNormalMode )
        ButtonSetPressedFlag( "EA_Window_InspectionTabsBragsTab", not inNormalMode )
        ButtonSetStayDownFlag( "EA_Window_InspectionTabsBragsTab", not inNormalMode )
    end
end

function EA_Window_Inspection.OnTabSelectChar()
    EA_Window_Inspection.UpdateMode( EA_Window_Inspection.MODE_NORMAL )
end

function EA_Window_Inspection.OnTabSelectBrags()
    EA_Window_Inspection.UpdateMode( EA_Window_Inspection.MODE_BRAGS )
end

function EA_Window_Inspection.UpdateBraggingRights()
    EA_Window_Inspection.bragData = GetInspectionBragData()
    
    for index, brag in ipairs( EA_Window_Inspection.bragData )
    do
        local windowName = "EA_Window_InspectionBragsEntry"..index
        local anchorWindow = "EA_Window_InspectionBragsEntry"..index-1
        if( index <= 1 )
        then
            anchorWindow = "EA_Window_InspectionBragsAnchor"
        end
    
        -- create a window for this brag if it doesn't exist
        if( not DoesWindowExist( windowName ) )
        then
            CreateWindowFromTemplate( windowName, "InspectionWindowBraggingRightTemplate", "EA_Window_InspectionBrags" )
            WindowAddAnchor( windowName, "bottom", anchorWindow, "top", 0, 0 )
        end
        
        WindowSetId( windowName, index )
        
        LabelSetText( windowName.."Text", brag.name )

        -- set the reward data
        if( not brag.rewards )
        then
            WindowSetShowing( windowName.."Reward1", false )
            WindowSetShowing( windowName.."Reward2", false )
        else
            EA_Window_Inspection.SetTomeReward( windowName.."Reward1", brag.rewards[1] )
            EA_Window_Inspection.SetTomeReward( windowName.."Reward2", brag.rewards[2] )
            
            -- Anchor card to left most reward
            anchorCardTo = windowName.."Reward1"
            if( brag.rewards[2] and brag.rewards[2].rewardId and brag.rewards[2].rewardId ~= 0 )
            then
                anchorCardTo = windowName.."Reward2"
            end
            WindowClearAnchors( windowName.."Card" )
            WindowAddAnchor( windowName.."Card", "topleft", anchorCardTo, "topright", 0, 0 )
        end
        
        -- Set the card if there is one
        local cardData = nil
        if( brag.cardData.cardId and brag.cardData.cardId ~= 0 )
        then
            cardData = brag.cardData
        end
        TomeWindow.SetCard( windowName.."Card", cardData )
    end
    
end

function EA_Window_Inspection.SetTomeReward( rewardWindowName, rewardData )

    if( rewardData == nil ) then
        WindowSetShowing( rewardWindowName, false )
        return
    end
    
    if( rewardData.rewardId == 0 ) then
        WindowSetShowing( rewardWindowName, false )
        return
    end
    
    WindowSetShowing( rewardWindowName, true )

    local iconNum = 0
    
    --Set up the icon for the reward
    if( GameData.Tome.REWARD_XP == rewardData.rewardType )
    then
        iconNum = GameDefs.Icons.ICON_XP_REWARD
        
    elseif( GameData.Tome.REWARD_TITLE == rewardData.rewardType )
    then
        iconNum = GameDefs.Icons.ICON_TITLE_REWARD
    
    elseif( rewardData.rewardData.iconNum )
    then
        iconNum = rewardData.rewardData.iconNum
        
    end    

    local texture, x, y = GetIconData( iconNum )        
    DynamicImageSetTexture( rewardWindowName.."IconBase", texture, x, y )  
end

function EA_Window_Inspection.OnMouseOverReward()
    local bragIndex = WindowGetId( WindowGetParent( SystemData.ActiveWindow.name ) )
    local rewardIndex = WindowGetId(  SystemData.ActiveWindow.name )

    local rewardType = EA_Window_Inspection.bragData[bragIndex].rewards[rewardIndex].rewardType
    local rewardId = EA_Window_Inspection.bragData[bragIndex].rewards[rewardIndex].rewardId
    local rewardData = EA_Window_Inspection.bragData[bragIndex].rewards[rewardIndex].rewardData
    
    if( rewardId == 0 ) then     
       return
    end
    
    local rewardWindowName = SystemData.ActiveWindow.name
    local anchor = Tooltips.ANCHOR_RIGHT

    --Set up the icon for the reward
    if( GameData.Tome.REWARD_ITEM == rewardType )
    then
        Tooltips.CreateItemTooltip( rewardData, rewardWindowName, anchor )
        
    elseif( GameData.Tome.REWARD_ABILITY == rewardType )
    then
        Tooltips.CreateAbilityTooltip( rewardData, rewardWindowName, anchor )
        
    elseif( GameData.Tome.REWARD_XP == rewardType )
    then
        local text = GetStringFormat( StringTables.Default.LABEL_X_XP, {rewardId}  )
        Tooltips.CreateTextOnlyTooltip( rewardWindowName, text )
        Tooltips.AnchorTooltip( anchor )
        
    elseif( GameData.Tome.REWARD_TITLE == rewardType )
    then
        local name = L"???"
        if( rewardData ~= nil ) then
            name = rewardData.name
        end
        local text = GetStringFormat( StringTables.Default.LABEL_TITLE_X, { name }  )
        local actionText = GetString( StringTables.Default.TEXT_CLICK_TITLE_LINK )
        Tooltips.CreateTextOnlyTooltip( rewardWindowName, text )
        Tooltips.SetTooltipActionText( actionText )
        Tooltips.Finalize()
        
        Tooltips.AnchorTooltip( anchor )
    end  
end

function EA_Window_Inspection.OnMouseOverCard()
    local cardId = WindowGetId( SystemData.ActiveWindow.name )
    local bragIndex = WindowGetId( WindowGetParent( SystemData.ActiveWindow.name ) )
    local cardData = EA_Window_Inspection.bragData[bragIndex].cardData
    local cardWindowName = SystemData.ActiveWindow.name
    local actionTextId = StringTables.Default.TEXT_CLICK_CARD_LINK
    local anchor = Tooltips.ANCHOR_WINDOW_RIGHT

    -- No valid card data
    if( cardData == nil ) then
        return
    end
    
    -- Build tool tip
    local cardName = GetFormatStringFromTable( "Default", StringTables.Default.TEXT_CARD_NAME, { cardData.valueName, cardData.suitName } )
    local cardColor = DataUtils.GetItemRarityColor( cardData )
    
    Tooltips.CreateTextOnlyTooltip( cardWindowName, nil )
    Tooltips.SetTooltipText( 1, 1, cardName )
    Tooltips.SetTooltipColor( 1, 1, cardColor.r, cardColor.g, cardColor.b )
    
    local unlockText = nil
    local actionText = nil
    if( cardData.unlockInfo.section ~= 0 and cardData.unlockInfo.entry ~= 0 )
    then
        local params = { DataUtils.GetTomeSectionName( cardData.unlockInfo.section ), cardData.unlockInfo.name }
        unlockText = GetStringFormat( StringTables.Default.TEXT_TOME_ENTRY_SOURCE, params )
    else
        unlockText = L""
    end
    
    Tooltips.SetTooltipText( 2, 1, unlockText )
    Tooltips.SetTooltipColorDef( 2, 1, Tooltips.COLOR_HEADING )
    
    if( actionTextId )
    then
        Tooltips.SetTooltipActionText( GetString( actionTextId ) )
    end
    Tooltips.Finalize()
    
    Tooltips.AnchorTooltip( anchor )
end

function EA_Window_Inspection.OnClickReward()
    local bragIndex = WindowGetId( WindowGetParent( SystemData.ActiveWindow.name ) )
    local rewardIndex = WindowGetId(  SystemData.ActiveWindow.name )

    local rewardData = EA_Window_Inspection.bragData[bragIndex].rewards[rewardIndex]
    TomeWindow.OnClickTomeReward( rewardData )
end

function EA_Window_Inspection.OnClickCard()
    local bragIndex = WindowGetId( WindowGetParent( SystemData.ActiveWindow.name ) )
    local cardData = EA_Window_Inspection.bragData[bragIndex].cardData
    
    TomeWindow.OnClickTomeCard( cardData )
end


-- this gets called during intitialization and for level up events in case a new slot becomes unlocked
function EA_Window_Inspection.UnlockTrophies()
    
    local userLevel = TargetInfo:UnitLevel("selffriendlytarget")
    if userLevel < 1 then
        return
    end
    
    EA_Window_Inspection.numOfTrophiesUnlocked = math.floor(userLevel / 10) + 1
    
    -- unlocked
    for trophyNum = 1, EA_Window_Inspection.numOfTrophiesUnlocked do
        ButtonSetDisabledFlag( "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS), false )
        
        local text = GetStringFormat( StringTables.Default.LABEL_TROPHY, { trophyNum } )
        EA_Window_Inspection.EquipmentSlotInfo[trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS] =  { name=text} 
        
        local lockIconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."LockIcon"
        WindowSetShowing( lockIconWindowName, false )
    end
    
    -- locked
    -- icon is now assembled from the untinted icon with a lock mini-icon on top
    for trophyNum = EA_Window_Inspection.numOfTrophiesUnlocked+1, EA_Window_Inspection.NUM_TROPHY_SLOTS do
    
        ButtonSetDisabledFlag( "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS), true )
        local windowName = "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."IconBase"
        local icon = EA_Window_Inspection.TROPHY_EMPTY_ICON
        DynamicImageSetTexture( windowName, icon.texture, icon.x, icon.y)

        local requiredLevel = (trophyNum-1) * 10
        
        local text1 = GetStringFormat( StringTables.Default.LABEL_TROPHY, { trophyNum } )
        local text2 = GetStringFormat( StringTables.Default.LABEL_TROPHY_LOCKED, { requiredLevel } )
        EA_Window_Inspection.EquipmentSlotInfo[trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS] =  { name=text1..L"\n"..text2 } 
        
        local lockIconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."LockIcon"
        lockIcon = EA_Window_Inspection.TROPHY_LOCKED_ICON
        DynamicImageSetTexture( lockIconWindowName, lockIcon.texture, lockIcon.x, lockIcon.y)
        WindowSetShowing( lockIconWindowName, true )
        
        local miniIconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."MiniIcon"
        WindowSetShowing( miniIconWindowName, false )
    end
    
    EA_Window_Inspection.UpdateSlotIcons()
end

-- provides the ItemInfo corresponding to the given slot
function EA_Window_Inspection.GetItem( slot )

    if slot < GameData.Player.c_TROPHY_START_INDEX then
        return EA_Window_Inspection.equipmentData[slot]

    else
        local trophySlot = slot - GameData.Player.c_TROPHY_START_INDEX + 1	
        return EA_Window_Inspection.trophyData[trophySlot]
    end
end


function EA_Window_Inspection.getFirstAvailableTrophySlot( trophyData )

    for slot = 1, EA_Window_Inspection.numOfTrophiesUnlocked do
        if EA_Window_Inspection.trophyData[slot].uniqueID == 0 then
            return slot
        end
    end
    
    return EA_Window_Inspection.INVALID_TROPHY_POSITION
end

function EA_Window_Inspection.validLocationForTrophy( trophyData, attachPoint )

    if attachPoint.inUse then
        return false
    end
    
    -- only need to check slot restrictions if the slotReqs table is set
    if trophyData.slots == nil or #trophyData.slots == 0 then
        return true
    end
    
    for _, slotAllowed in ipairs(trophyData.slots) do
        if attachPoint.inventorySlotNum == slotAllowed then
            return true		-- found as a valid slot
        end
    end
    
    return false		-- wasn't found in the valid slot list

end

-- if trophyData is nil then return any open attachment point
-- TODO: we need to limit this to valid locations for the passed in trophyData
--
-- if startIndex is set start search from that point
-- and wrap around the last index number to check 1 to startIndex-1
--
function EA_Window_Inspection.getNextAvailableAttachmentPoint( trophyData, startIndex )
--DEBUG(L"EA_Window_Inspection.getNextAvailableAttachmentPoint")

    if #EA_Window_Inspection.trophyLocData == 0 then
        return 0, nil
    end
    
    startIndex = startIndex or 1
    local attachPoint

    for index = startIndex, #EA_Window_Inspection.trophyLocData do
    --DEBUG(L"checking index "..index)
        attachPoint = EA_Window_Inspection.trophyLocData[index]
        if EA_Window_Inspection.validLocationForTrophy( trophyData, attachPoint ) then
            return index, attachPoint 
        end
    end
    
    for index = 1, (startIndex-1) do
    --DEBUG(L"checking index "..index)
        attachPoint = EA_Window_Inspection.trophyLocData[index]
        if EA_Window_Inspection.validLocationForTrophy( trophyData, attachPoint ) then
            return index, attachPoint 
        end
    end

--DEBUG(L"EA_Window_Inspection.getNextAvailableAttachmentPoint nothing found")

    return 0, nil
end


-- Does the reverse order search of EA_Window_Inspection.getNextAvailableAttachmentPoint 
--
-- if trophyData is nil then return any open attachment point
-- TODO: we need to limit this to valid locations for the passed in trophyData
--
-- if startIndex is set start search from that point
-- and wrap around the last index number to check 1 to startIndex-1
--
function EA_Window_Inspection.getPreviousAvailableAttachmentPoint( trophyData, startIndex )
--DEBUG(L"EA_Window_Inspection.getPreviousAvailableAttachmentPoint")

    if #EA_Window_Inspection.trophyLocData == 0 then
        return 0, nil
    end
    
    if startIndex < 1 then
        startIndex = #EA_Window_Inspection.trophyLocData
    end
    
    --DEBUG(L"  passed in startIndex = "..startIndex)
    startIndex = startIndex or #EA_Window_Inspection.trophyLocData
    
    --DEBUG(L"  new startIndex = "..startIndex)
    local attachPoint

    for index = startIndex, 1, -1 do
    --DEBUG(L"checking index "..index)
        attachPoint = EA_Window_Inspection.trophyLocData[index]
        if EA_Window_Inspection.validLocationForTrophy( trophyData, attachPoint ) then
            return index, attachPoint 
        end
    end
    --DEBUG(L"checking2 looping from  #EA_Window_Inspection.trophyLocData"..#EA_Window_Inspection.trophyLocData..L" to "..(startIndex+1))
    for index = #EA_Window_Inspection.trophyLocData, (startIndex+1), -1 do
    --DEBUG(L"checking2 index "..index)
        attachPoint = EA_Window_Inspection.trophyLocData[index]
        if EA_Window_Inspection.validLocationForTrophy( trophyData, attachPoint ) then
            return index, attachPoint 
        end
    end
    
--DEBUG(L"EA_Window_Inspection.getPreviousAvailableAttachmentPoint nothing found")
    return 0, nil
end

function EA_Window_Inspection.hightlightSlot( windowName )
    
    ButtonSetStayDownFlag( windowName, true )     
    ButtonSetPressedFlag( windowName, true )
end

function EA_Window_Inspection.unhightlightSlot( windowName )
    
    ButtonSetStayDownFlag( windowName, false )     
    ButtonSetPressedFlag( windowName, false )
end

function EA_Window_Inspection.hideTrophyLocArrows()

--    WindowSetShowing( "EA_Window_InspectionPreviousButton", false )
--    WindowSetShowing( "EA_Window_InspectionNextButton", false )
    
    if EA_Window_Inspection.currentlySelectedTrophyPosition ~= EA_Window_Inspection.INVALID_TROPHY_POSITION then
        local previousWindow = "EA_Window_InspectionContentsEquipmentSlot"..(EA_Window_Inspection.currentlySelectedTrophyPosition+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS)
        EA_Window_Inspection.unhightlightSlot( previousWindow )
        EA_Window_Inspection.currentlySelectedTrophyPosition = EA_Window_Inspection.INVALID_TROPHY_POSITION 
    end 

    WindowUnregisterEventHandler( "EA_Window_Inspection", SystemData.Events.L_BUTTON_DOWN_PROCESSED )
end


function EA_Window_Inspection.showTrophyLocArrows( trophyNum )

    local previousWindow = "EA_Window_InspectionContentsEquipmentSlot"..(EA_Window_Inspection.currentlySelectedTrophyPosition+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS)
    EA_Window_Inspection.unhightlightSlot( previousWindow )
    
    -- trophy windows are grouped with other equipment slots
    local windowName = "EA_Window_InspectionContentsEquipmentSlot"..(trophyNum+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS) 
    
--    WindowClearAnchors( "EA_Window_InspectionPreviousButton" )
--    WindowAddAnchor( "EA_Window_InspectionPreviousButton", "left", windowName, "right", -5, 0 )
--    WindowSetShowing( "EA_Window_InspectionPreviousButton", true )

--    WindowClearAnchors( "EA_Window_InspectionNextButton" )
--    WindowAddAnchor( "EA_Window_InspectionNextButton", "right", windowName, "left", 5, 0 )
--    WindowSetShowing( "EA_Window_InspectionNextButton", true )
    
    EA_Window_Inspection.hightlightSlot( windowName )
    EA_Window_Inspection.currentlySelectedTrophyPosition = trophyNum
    
    -- there is no way to see if already registered so we go ahead and unregister first to avoid the lua error from duplicate register
    WindowUnregisterEventHandler( "EA_Window_Inspection", SystemData.Events.L_BUTTON_DOWN_PROCESSED )
    WindowRegisterEventHandler( "EA_Window_Inspection", SystemData.Events.L_BUTTON_DOWN_PROCESSED, "EA_Window_Inspection.OnLButtonDownProcessed") 
end

-- EventHandler for OnLButtonDownProcessed, which is only temporarily registered in order to deactivate 
--   the TrophyLocArrows when clicking off of them
--
function EA_Window_Inspection.OnLButtonDownProcessed( )
    
    --DEBUG(L"EA_Window_Inspection.OnLButtonDownProcessed")
    local windowName = SystemData.MouseOverWindow.name
    local currentTrophyWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(EA_Window_Inspection.currentlySelectedTrophyPosition+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS)

    if windowName ~= nil and windowName ~= currentTrophyWindowName and 
       windowName ~= "EA_Window_InspectionPreviousButton" and windowName ~= "EA_Window_InspectionNextButton" then
        EA_Window_Inspection.hideTrophyLocArrows()
        EA_Window_Inspection.trophyDragStarted = false
    end

end

function EA_Window_Inspection.NextButtonPressed()

    if EA_Window_Inspection.currentlySelectedTrophyPosition == EA_Window_Inspection.INVALID_TROPHY_POSITION then  
        -- this should never be true
        return
    end
    
    local trophyData = EA_Window_Inspection.trophyData[EA_Window_Inspection.currentlySelectedTrophyPosition]
    
    local startIndex = EA_Window_Inspection.getIndexForTrophyLoc( trophyData.trophyLocation, trophyData.trophyLocIndex )
    local index, attachPointData = EA_Window_Inspection.getNextAvailableAttachmentPoint( trophyData, startIndex+1 )
    if index ~= 0 then
        AttachTrophyToLocation( EA_Window_Inspection.currentlySelectedTrophyPosition, attachPointData.trophyLocation, attachPointData.trophyLocIndex)
    end
end


function EA_Window_Inspection.NextButtonMouseOver()

    Tooltips.CreateTextOnlyTooltip( "EA_Window_InspectionNextButton", EA_Window_Inspection.TOOLTIP_TROPHY_NEXT_LOC )
    Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_RIGHT)
end


function EA_Window_Inspection.PreviousButtonPressed()

    if EA_Window_Inspection.currentlySelectedTrophyPosition == EA_Window_Inspection.INVALID_TROPHY_POSITION then  
        -- this should never be true
        return
    end
    
    local trophyData = EA_Window_Inspection.trophyData[EA_Window_Inspection.currentlySelectedTrophyPosition]
    
    local startIndex = EA_Window_Inspection.getIndexForTrophyLoc( trophyData.trophyLocation, trophyData.trophyLocIndex )
    local index, attachPointData = EA_Window_Inspection.getPreviousAvailableAttachmentPoint( trophyData, startIndex-1 )
    if index ~= 0 then
        AttachTrophyToLocation( EA_Window_Inspection.currentlySelectedTrophyPosition, attachPointData.trophyLocation, attachPointData.trophyLocIndex)
    end	
end

function EA_Window_Inspection.PreviousButtonMouseOver()

    Tooltips.CreateTextOnlyTooltip( "EA_Window_InspectionPreviousButton", EA_Window_Inspection.TOOLTIP_TROPHY_PREV_LOC )
    Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_LEFT)
end


-- OnUpdate Handler
function EA_Window_Inspection.Update( timePassed )

    local showing = WindowGetShowing( "EA_Window_Inspection" )
    if( showing ) then  
        BroadcastEvent( SystemData.Events.UPDATE_TARGETPAPERDOLL )    
        EA_Window_Inspection.UpdateStatsNew()
    end

    if( GameData.Player.activeTitle ~= nil and GameData.Player.activeTitle ~= EA_Window_Inspection.currentTitleSelection ) then
        --EA_Window_Inspection.UpdateTitleLabel()
    end
end

-- OnShutdown Handler
function EA_Window_Inspection.Shutdown()
    WindowSetShowing("EA_Window_Inspection", false )
    WindowUnregisterEventHandler( "EA_Window_Inspection", SystemData.Events.L_BUTTON_DOWN_PROCESSED )
    SetPaperDollBackground( "", 0, 0 )
end

function EA_Window_Inspection.RefreshContents()
    EA_Window_Inspection.UnlockTrophies() 
    EA_Window_Inspection.UpdateBraggingRights()
end

-- OnShown Handler
function EA_Window_Inspection.OnShown()
   WindowUtils.OnShown(EA_Window_Inspection.Hide, WindowUtils.Cascade.MODE_AUTOMATIC)

   EA_Window_Inspection.RefreshContents()
end

function EA_Window_Inspection.ToggleShowing()   
    WindowUtils.ToggleShowing( "EA_Window_Inspection" )
end

function EA_Window_Inspection.Show() 
	LabelSetText( "EA_Window_InspectionContentsImageNameLabel", TargetInfo:UnitName("selffriendlytarget") )
	LabelSetText( "EA_Window_InspectionBragsHeader", GetStringFormat( StringTables.Default.LABEL_PLAYERS_BRAGS_HEADER, {TargetInfo:UnitName("selffriendlytarget")} ) )
    
    if (WindowGetShowing("EA_Window_Inspection"))
    then  
        EA_Window_Inspection.RefreshContents()
    else
        WindowSetShowing("EA_Window_Inspection", true)
    end
end

function EA_Window_Inspection.Hide() 
    WindowSetShowing("EA_Window_Inspection", false)
end

function EA_Window_Inspection.getSlotInfoForTrophyLocation( location, index )

    for slot, clothingInfo in pairs( EA_Window_Inspection.ClothingSlotInfo ) do
    
        if clothingInfo.trophyLocation == location and clothingInfo.trophyLocIndex == index then
            return slot
        end
    end
    
    return 0
end


function EA_Window_Inspection.getIndexForTrophyLoc( location, index )

    if EA_Window_Inspection.trophyLocData == nil then
        return 0, nil
    end

    for apIndex, attachPoint in pairs( EA_Window_Inspection.trophyLocData ) do
        if attachPoint.trophyLocation == location and attachPoint.trophyLocIndex == index then
            return apIndex, attachPoint
        end
    end
    
    return 0, nil
end


function EA_Window_Inspection.UpdateSlotIcons()
    --DEBUG(L"EA_Window_Inspection.UpdateSlotIcons")  

    local texture, x, y  = 0, 0, 0
    local tint = EA_Window_Inspection.NORMAL_TINT 
    
    EA_Window_Inspection.equipmentData = GetInspectionData()
    --DUMP_TABLE(EA_Window_Inspection.equipmentData)
    for equipmentData, slot in pairs(GameData.EquipSlots) do
		--DEBUG(L"slot = "..slot)
		--DEBUG(L"equipmentData = "..StringToWString(equipmentData))
    
        if( EA_Window_Inspection.equipmentData[slot].iconNum ~= 0) then
            texture, x, y = GetIconData( EA_Window_Inspection.equipmentData[slot].iconNum ) 
            tint = EA_Window_Inspection.NORMAL_TINT
        else
            texture, x, y = GetIconData( EA_Window_Inspection.EquipmentSlotInfo[slot].iconNum )  
            tint = EA_Window_Inspection.EQUIPMENT_EMPTY_TINT 
        end     

        DynamicImageSetTexture( "EA_Window_InspectionContentsEquipmentSlot"..slot.."IconBase", texture, x, y )
--        WindowSetTintColor( "EA_Window_InspectionEquipmentSlot"..slot, tint.R, tint.G, tint.B )
    end
    
    EA_Window_Inspection.trophyLocData = GetLocationsForTrophies()	-- provides list of available attachment points
    EA_Window_Inspection.trophyData = GetTrophyData()				-- provides item info for all trophy slots (may be blank data)
    EA_Window_Inspection.numOfTrophiesEquipped = 0
    
    local unattachedTrophies = {}
    
    for  slot = 1, EA_Window_Inspection.numOfTrophiesUnlocked  do  
        local trophyData = EA_Window_Inspection.equipmentData[slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS]
        local miniIconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."MiniIcon"

        if( trophyData ~= nil and trophyData.uniqueID ~= 0) then
            texture, x, y = GetIconData( trophyData.iconNum ) 
            tint = EA_Window_Inspection.NORMAL_TINT
            
            local index, attachPoint = EA_Window_Inspection.getIndexForTrophyLoc( trophyData.trophyLocation, trophyData.trophyLocIndex )

            EA_Window_Inspection.numOfTrophiesEquipped = EA_Window_Inspection.numOfTrophiesEquipped + 1
        else
        
            -- display empty trophy slot icon
            local icon = EA_Window_Inspection.TROPHY_EMPTY_ICON
            texture, x, y = icon.texture, icon.x, icon.y
            tint = EA_Window_Inspection.TROPHY_EMPTY_TINT

            WindowSetShowing( miniIconWindowName, false )
        end     
        
         -- trophy windows are grouped with other equipment slots
        local iconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."IconBase"
        DynamicImageSetTexture( iconWindowName, texture, x, y )
--        WindowSetTintColor( "EA_Window_InspectionEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS), tint.R, tint.G, tint.B )

    end 
    
    -- now loop through the unattached trophies and provide the appropriate mini icon and tooltip
    local icon
    for slot, trophyData in pairs(unattachedTrophies) do
    
        local miniIconWindowName = "EA_Window_InspectionContentsEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS).."MiniIcon"
        local availableIndex = EA_Window_Inspection.getNextAvailableAttachmentPoint( trophyData )
        
        if availableIndex == 0 then
            -- there are no available locations for this trophy
            icon = EA_Window_Inspection.TROPHY_NO_ATTACHMENT_POINT_ICON
            trophyData.tooltip = EA_Window_Inspection.TOOLTIP_TROPHY_NO_AVAILABLE_LOC 
        else 
            -- the current set location is not available
            icon = EA_Window_Inspection.TROPHY_INVALID_ATTACHMENT_POINT_ICON 
            trophyData.tooltip = EA_Window_Inspection.TOOLTIP_TROPHY_INVALID_LOC 
        end
        
        DynamicImageSetTexture( miniIconWindowName, icon.texture, icon.x, icon.y )
    end
    
end


-- OnLButtonDown Handler
function EA_Window_Inspection.EquipmentLButtonDown()

    local slot = WindowGetId(SystemData.ActiveWindow.name)
    
    if( Cursor.UseItemTargeting ) then
        --Attempt to use the target item on the selected slot
        UseItemTargeting.HandleUseItemOnTarget(Cursor.SOURCE_EQUIPMENT, slot)
    elseif Cursor.IconOnCursor() then
        
        -- Attempt to drop the object
        RequestMoveItem( Cursor.Data.Source, Cursor.Data.SourceSlot, Cursor.SOURCE_EQUIPMENT, slot, Cursor.Data.StackAmount )   
        EA_Window_Inspection.dropPending = true  
    else
                
        if EA_Window_Inspection.equipmentData[slot].uniqueID ~= 0 then
            --DEBUG(L"EA_Window_Inspection.EquipmentLButtonDown pickup")
            Cursor.PickUp( Cursor.SOURCE_EQUIPMENT, slot, EA_Window_Inspection.equipmentData[slot].uniqueID, EA_Window_Inspection.equipmentData[slot].iconNum, true )           
            EA_Window_Inspection.unhightlightSlot( "EA_Window_InspectionContentsEquipmentSlot"..slot  )
        end
        
        EA_Window_Inspection.dropPending = false
    end
end


-- OnLButtonDown Handler
function EA_Window_Inspection.TrophyLButtonDown()

    local slot = WindowGetId(SystemData.ActiveWindow.name)
    if Cursor.IconOnCursor() then
        
        local trophyIndex = slot + GameData.Player.c_TROPHY_START_INDEX - 1
        RequestMoveItem( Cursor.Data.Source, Cursor.Data.SourceSlot, Cursor.SOURCE_EQUIPMENT, trophyIndex, Cursor.Data.StackAmount)  

        -- retrieve inventorySlot's item data from BackpackWindow
        local invData = DataUtils.GetItems()
        local itemData = invData[Cursor.Data.SourceSlot]

        -- should auto equp to first available attachment point
        EA_Window_Inspection.AutoAttachTrophy( slot, itemData )
        
        EA_Window_Inspection.dropPending = true  
        
    elseif EA_Window_Inspection.trophyData[slot].uniqueID ~= 0 then	
        
        -- first click on the slot turns on trophy attachment buttons
        -- second click, needs to be done to cause pick up onto cursor
        -- click and hold should always pick up onto cursor
        if EA_Window_Inspection.currentlySelectedTrophyPosition ~= slot then
            EA_Window_Inspection.showTrophyLocArrows( slot )
        else
            --DEBUG(L"EA_Window_Inspection.TrophyLButtonDown pickup")
            local trophySlot = slot + GameData.Player.c_TROPHY_START_INDEX - 1	
            Cursor.PickUp( Cursor.SOURCE_EQUIPMENT, trophySlot, EA_Window_Inspection.trophyData[slot].uniqueID, EA_Window_Inspection.trophyData[slot].iconNum, true )   
            EA_Window_Inspection.hideTrophyLocArrows()
            
        end
        
        EA_Window_Inspection.dropPending = false  
    end
end

-- MouseDrag Handler on Trophy slots ( for drag & drop )
function EA_Window_Inspection.TrophyDrag()
    
    -- have to skip the first TrophyDrag to wait and see if this is a single click (which also throws the OnDrag event)
    if not EA_Window_Inspection.trophyDragStarted then
        EA_Window_Inspection.trophyDragStarted = true
        return
    end

    local slot = WindowGetId(SystemData.ActiveWindow.name)
    if not Cursor.IconOnCursor() and EA_Window_Inspection.trophyData[slot].uniqueID ~= 0 and EA_Window_Inspection.currentlySelectedTrophyPosition == slot then
        
        --DEBUG(L"EA_Window_Inspection.TrophyDrag pickup")
        EA_Window_Inspection.trophyDragStarted = false
        local trophySlot = slot + GameData.Player.c_TROPHY_START_INDEX - 1	
        Cursor.PickUp( Cursor.SOURCE_EQUIPMENT, trophySlot, EA_Window_Inspection.trophyData[slot].uniqueID, EA_Window_Inspection.trophyData[slot].iconNum, true )   
        EA_Window_Inspection.hideTrophyLocArrows()
    end
    
end

-- OnLButtonUp Handler ( Overload L Button up for drag & drop )
function EA_Window_Inspection.EquipmentLButtonUp()

    if Cursor.IconOnCursor() and EA_Window_Inspection.dropPending == false then
        
        local slot = WindowGetId(SystemData.ActiveWindow.name)
        
        --DEBUG(L"EA_Window_Inspection.EquipmentLButtonUp dropping icon")
        -- Attempt to drop the object
        RequestMoveItem( Cursor.Data.Source, Cursor.Data.SourceSlot, Cursor.Data.SOURCE_EQUIPMENT, slot, Cursor.Data.StackAmount )    
  
    end
end

-- OnLButtonUp Handler ( Overload L Button up for drag & drop )
function EA_Window_Inspection.TrophyLButtonUp()
    --DEBUG(L"EA_Window_Inspection.TrophyLButtonUp")

    EA_Window_Inspection.trophyDragStarted = false
    if Cursor.IconOnCursor() and EA_Window_Inspection.dropPending == false then
        
        --DEBUG(L"EA_Window_Inspection.TrophyLButtonUp dropping icon")
        local slot = WindowGetId(SystemData.ActiveWindow.name)
        local trophyIndex = slot + GameData.Player.c_TROPHY_START_INDEX - 1
        RequestMoveItem( Cursor.Data.Source, Cursor.Data.SourceSlot, Cursor.SOURCE_EQUIPMENT, trophyIndex)   
        
        -- retrieve inventorySlot's item data from BackpackWindow
        local invData = DataUtils.GetItems()
        local itemData = invData[Cursor.Data.SourceSlot]
        
        -- should auto equp to first available attachment point
        EA_Window_Inspection.AutoAttachTrophy( slot, itemData )
    end
end


-- OnRButtonDown Handler
function EA_Window_Inspection.EquipmentRButtonDown()
    local slot = WindowGetId(SystemData.ActiveWindow.name)
    
    -- verify that we're clicking on an icon before spamming the server
    if not Cursor.IconOnCursor() and EA_Window_Inspection.equipmentData[slot].uniqueID ~= 0 then
    
        -- Attempt to put this item back into the inventory
        RequestMoveItem( Cursor.SOURCE_EQUIPMENT, slot, Cursor.SOURCE_INVENTORY, EA_Window_Inspection.FIRST_AVAILABLE_INVENTORY_SLOT, Cursor.Data.StackAmount)
    end
end


-- OnRButtonDown Handler
function EA_Window_Inspection.TrophyRButtonDown()
    
    EA_Window_Inspection.trophyDragStarted = false
    local slot = WindowGetId(SystemData.ActiveWindow.name)
    
    -- verify that we're clicking on an icon before spamming the server
    if not Cursor.IconOnCursor() and EA_Window_Inspection.trophyData[slot].uniqueID ~= 0  then
    
        local trophyIndex = slot + GameData.Player.c_TROPHY_START_INDEX - 1
        RequestMoveItem( Cursor.SOURCE_EQUIPMENT, trophyIndex, Cursor.SOURCE_INVENTORY, EA_Window_Inspection.FIRST_AVAILABLE_INVENTORY_SLOT, Cursor.Data.StackAmount)
        EA_Window_Inspection.hideTrophyLocArrows()
    end
end


-- if itemData does not contain a valid attachment point
-- then try to auto attach to first available attachment point
--  
function EA_Window_Inspection.AutoAttachTrophy( trophySlot, itemData )

    -- check if there is a previous attachment position (from being previously attached) and if that is still valid
    if itemData ~= nil then
        
        local apIndex, apData = EA_Window_Inspection.getIndexForTrophyLoc( itemData.trophyLocation, itemData.trophyLocIndex )
        
        if ( apIndex ~= 0 and EA_Window_Inspection.validLocationForTrophy( itemData, apData ) ) then
            return
        end
    end
    
    local index, attachPointData = EA_Window_Inspection.getNextAvailableAttachmentPoint( itemData )
    if index ~= 0 then
        AttachTrophyToLocation( trophySlot, attachPointData.trophyLocation, attachPointData.trophyLocIndex)
    end
end

function EA_Window_Inspection.DropItemIntoEquipment()

    if ( Cursor.IconOnCursor() and Cursor.Data.Source == Cursor.SOURCE_INVENTORY ) then
        EA_Window_Inspection.AutoEquipItem( Cursor.Data.SourceSlot )
    end
end

-- note that this function may be called directly from the BackpackWindow
--
function EA_Window_Inspection.AutoEquipItem( inventorySlot )
        
    -- retrieve inventorySlot's item data from BackpackWindow
    local invData = DataUtils.GetItems()
    local itemData = invData[inventorySlot]

    if (itemData ~= nil and itemData.type == GameData.ItemTypes.TROPHY) then
        
        local trophySlot = EA_Window_Inspection.getFirstAvailableTrophySlot( itemData )
        if trophySlot ~= EA_Window_Inspection.INVALID_TROPHY_POSITION then 		
        
            -- Server is responsible for checking requirements for whether user meets trophy requirements
            --   so we don't pre-set trophy icon
            local trophyIndex = trophySlot + GameData.Player.c_TROPHY_START_INDEX - 1

            if (Cursor.Data == nil) then
                RequestMoveItem( Cursor.SOURCE_INVENTORY, inventorySlot, Cursor.SOURCE_EQUIPMENT, trophyIndex, 0) 
            else
                RequestMoveItem( Cursor.SOURCE_INVENTORY, inventorySlot, Cursor.SOURCE_EQUIPMENT, trophyIndex, Cursor.Data.StackAmount) 
            end
            
            EA_Window_Inspection.AutoAttachTrophy( trophySlot, itemData )
        end
    else
        AutoEquipItem( inventorySlot )      
    end
end

-- SystemData.Events.PLAYER_EQUIPMENT_SLOT_UPDATED Handler
function EA_Window_Inspection.UpdateEquipmentSlot()
    
    -- We'll stick to this for now but as soon as possible we must switch to updating
    -- ONLY the slot with the concerned item.
    
    local slot = GameData.Player.Equipment.UpdatedIndex
    if( not EA_Window_Inspection.initializationComplete or slot == 0 ) then
        return  
    end     
    
    EA_Window_Inspection.UpdateSlotIcons()
    
    local uniqueID = EA_Window_Inspection.equipmentData[slot].uniqueID
    
    -- If we are placing the item that is currently on the cursor, clear it
    if( Cursor.IconOnCursor() and (Cursor.Data.ObjectId == uniqueID or EA_Window_Inspection.dropPending == true) ) then 
        Cursor.Clear()  
    end
    
    -- If we are mousing over the updated slot, show the tooltip
    if SystemData.MouseOverWindow.name == "EA_Window_InspectionContentsEquipmentSlot"..slot then   
        EA_Window_Inspection.MouseOverSlot( slot )
    end
end



-- SystemData.Events.PLAYER_TROPHY_SLOT_UPDATED Handler
function EA_Window_Inspection.UpdateTrophySlot()
    
    -- We'll stick to this for now but as soon as possible we must switch to updating
    -- ONLY the slot with the concerned item.
    
    local slot = GameData.Player.Trophy.UpdatedIndex
    if( not EA_Window_Inspection.initializationComplete or slot == 0 ) then
        return  
    end     
    
    EA_Window_Inspection.UpdateSlotIcons()
   
    local uniqueID = EA_Window_Inspection.trophyData[slot].uniqueID
    -- If we are placing the item that is currently on the cursor, clear it
    if( Cursor.IconOnCursor() and (Cursor.Data.ObjectId == uniqueID or EA_Window_Inspection.dropPending == true) ) then 
        Cursor.Clear()  
    end
    
    -- If we are mousing over the updated slot, show the tooltip
    if SystemData.MouseOverWindow.name == "EA_Window_InspectionContentsEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS) then   
        
        EA_Window_Inspection.TrophyMouseOverSlot( slot )
    end
end


-- OnMouseMove Handler
function EA_Window_Inspection.EquipmentMouseOver()
    EA_Window_Inspection.MouseOverSlot( WindowGetId(SystemData.ActiveWindow.name) )
end 

function EA_Window_Inspection.MouseOverSlot( slot )

    if( EA_Window_Inspection.equipmentData[slot].id == 0 ) then        
        Tooltips.CreateTextOnlyTooltip( "EA_Window_InspectionContentsEquipmentSlot"..slot, nil )
        Tooltips.SetTooltipText( 1, 1, EA_Window_Inspection.EquipmentSlotInfo[slot].name )
        Tooltips.SetTooltipColor( 1, 1, 123, 172, 220 )
        Tooltips.Finalize()
        Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_RIGHT )
    else
        Tooltips.CreateItemTooltip( EA_Window_Inspection.equipmentData[slot], "EA_Window_InspectionContentsEquipmentSlot"..slot, Tooltips.ANCHOR_WINDOW_RIGHT, true )   
    end
end 


-- OnMouseMove Handler
function EA_Window_Inspection.TrophyMouseOver()
                            
    EA_Window_Inspection.TrophyMouseOverSlot( WindowGetId(SystemData.ActiveWindow.name) )
end


function EA_Window_Inspection.TrophyMouseOverSlot( slot )
    --DEBUG(L"EA_Window_Inspection.TrophyMouseOverSlot ")
    
    -- trophy windows are grouped with other equipment slots
    local windowName = "EA_Window_InspectionContentsEquipmentSlot"..(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS) 
    
    if( EA_Window_Inspection.equipmentData[slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS].uniqueID == 0 ) then     
       
        Tooltips.CreateTextOnlyTooltip( windowName, nil )
        Tooltips.SetTooltipText( 1, 1, EA_Window_Inspection.EquipmentSlotInfo[(slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS)].name )
        Tooltips.SetTooltipColor( 1, 1, 123, 172, 220 )
        Tooltips.Finalize()
        Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_RIGHT )
    else

        Tooltips.CreateItemTooltip( EA_Window_Inspection.equipmentData[slot+EA_Window_Inspection.NUM_EQUIPMENT_SLOTS], windowName, Tooltips.ANCHOR_WINDOW_RIGHT, true )   
    end
end 



-- TrophyMiniIconMouseOver is  commmented out because the tooltip on the mini icon 
--    is not working properly. It's repeatedly
--    firing OnMouseOver events rather than only sending it once.

function EA_Window_Inspection.TrophyMiniIconMouseOver()

    local windowName = SystemData.ActiveWindow.name
    local slot = WindowGetId( WindowGetParent( windowName ) )
    EA_Window_Inspection.TrophyMiniIconMouseOverSlot(windowName, slot)
end
    
function EA_Window_Inspection.TrophyMiniIconMouseOverSlot(windowName, slot)
    
    local trophyData = EA_Window_Inspection.trophyData[slot]
     
    local invalidTint = EA_Window_Inspection.TROPHY_INVALID_LOC_TINT
    Tooltips.CreateTextOnlyTooltip( windowName, nil )
    Tooltips.SetTooltipText( 1, 1, trophyData.tooltip )
    Tooltips.SetTooltipColor( 1, 1, invalidTint.r, invalidTint.g, invalidTint.b )
    Tooltips.Finalize()
    Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_RIGHT )
    
end

function EA_Window_Inspection.UpdateStats()
    
    local text = L""..GameData.Player.armorValue 
--    LabelSetText( "EA_Window_InspectionArmorValue", text )
    
    -- Round to the nearest decimal place.
    text = wstring.format(L"%.1f", GameData.Player.dpsValue)
--    LabelSetText( "EA_Window_InspectionDPSValue", text )

    for stat = 1, GameData.Stats.COUNT do        
    
--        if( StatInfo[stat].skip ~= true ) then  
        
--            text = L""..GameData.Player.Stats[stat].currentValue
--            LabelSetText( "Stat"..stat.."Value", text  )
            
--            if( GameData.Player.Stats[stat].currentValue > GameData.Player.Stats[stat].baseValue ) then
--                LabelSetTextColor( "Stat"..stat.."Value",  34, 253, 255 )
--            elseif( GameData.Player.Stats[stat].currentValue < GameData.Player.Stats[stat].baseValue ) then
--                LabelSetTextColor( "Stat"..stat.."Value",  231, 6, 20 )
--            else
--                LabelSetTextColor( "Stat"..stat.."Value",  227, 222, 120 )
--            end
            
--        end
    end
end

function EA_Window_Inspection.UpdateHitPoints()
    local text = L""..GameData.Player.hitPoints.maximum
--    LabelSetText( "EA_Window_InspectionHPValue", text )
end

function EA_Window_Inspection.OnMouseOverStat(stat)
    EA_Window_Inspection.CreateTooltip(SystemData.ActiveWindow.name, StatInfo[stat].name, StatInfo[stat].desc)
end

function EA_Window_Inspection.OnMouseOverArmorValue()
    EA_Window_Inspection.CreateTooltip(SystemData.ActiveWindow.name, GetString( StringTables.Default.LABEL_ARMOR ), GetString( StringTables.Default.TEXT_ARMOR ))
end

function EA_Window_Inspection.OnMouseOverDPSValue()
    EA_Window_Inspection.CreateTooltip(SystemData.ActiveWindow.name, GetString( StringTables.Default.LABEL_DAMAGE ), GetString( StringTables.Default.TEXT_DAMAGE ))
end

function EA_Window_Inspection.OnMouseOverHPValue()       
    EA_Window_Inspection.CreateTooltip(SystemData.ActiveWindow.name, GetString( StringTables.Default.LABEL_HIT_POINTS ), GetString( StringTables.Default.TEXT_HIT_POINTS ))
end

function EA_Window_Inspection.UpdateCareerRank()
    
    local career = GameData.Player.career.name
    local rank = TargetInfo:UnitLevel("selffriendlytarget")
    local rankText = GetStringFormat( StringTables.Default.LABEL_RANK_X, { rank } )
    
    EA_Window_Inspection.UnlockTrophies()
end 


function EA_Window_Inspection.armorHasAttachmentPoint( trophyLocation, trophyLocIndex )
    
    local slot = EA_Window_Inspection.getIndexForTrophyLoc( trophyLocation, trophyLocIndex )
    
    if slot ~= 0 then
        return true 
    end
    
    return false
end

function EA_Window_Inspection.UpdateStatCombobox()

    -- Clear ComboBox before populating to avoid duplicates
--    ComboBoxClearMenuItems("EA_Window_InspectionStatCombobox")
--	ComboBoxAddMenuItem("EA_Window_InspectionStatCombobox", GetString( StringTables.Default.LABEL_STATS ))
--	ComboBoxAddMenuItem("EA_Window_InspectionStatCombobox", GetString( StringTables.Default.LABEL_FILTER_OFFENSE ))
--	ComboBoxAddMenuItem("EA_Window_InspectionStatCombobox", GetString( StringTables.Default.LABEL_FILTER_DEFENSE ))

    -- Reset selections
    EA_Window_Inspection.currentStatSelection = 1
    EA_Window_Inspection.previousStatSelection = 0
--    ComboBoxSetSelectedMenuItem("EA_Window_InspectionStatCombobox", 1)
    EA_Window_Inspection.UpdateStatsLabels()
end

function EA_Window_Inspection.OnFilterSelChanged( curSel )
    EA_Window_Inspection.currentStatSelection = curSel
    EA_Window_Inspection.UpdateStatsNew()
end

function EA_Window_Inspection.UpdateStatsNew()
    if (EA_Window_Inspection.previousStatSelection == EA_Window_Inspection.currentStatSelection) then
        return
    end
    
    if EA_Window_Inspection.currentStatSelection == 1 then
        EA_Window_Inspection.UpdateStatsLabels()
    elseif EA_Window_Inspection.currentStatSelection == 2 then
        EA_Window_Inspection.UpdateOffenseLabels()
    elseif EA_Window_Inspection.currentStatSelection == 3 then
        EA_Window_Inspection.UpdateDefenseLabels()
    end

    EA_Window_Inspection.UpdateStatIcons()
    EA_Window_Inspection.previousStatSelection = EA_Window_Inspection.currentStatSelection
end

function EA_Window_Inspection.UpdateStatsLabels()
--    LabelSetText( "EA_Window_InspectionStatsWindow1Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_STRENGTH ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow1Right", L""..GameData.Player.Stats[GameData.Stats.STRENGTH].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow2Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_TOUGHNESS ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow2Right", L""..GameData.Player.Stats[GameData.Stats.TOUGHNESS].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow3Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_WOUNDS ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow3Right", L""..GameData.Player.Stats[GameData.Stats.WOUNDS].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow4Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_INITIATIVE ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow4Right", L""..GameData.Player.Stats[GameData.Stats.INITIATIVE].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow5Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_WEAPONSKILL ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow5Right", L""..GameData.Player.Stats[GameData.Stats.WEAPONSKILL].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow6Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_BALLISTICSKILL ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow6Right", L""..GameData.Player.Stats[GameData.Stats.BALLISTICSKILL].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow7Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_INTELLIGENCE ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow7Right", L""..GameData.Player.Stats[GameData.Stats.INTELLIGENCE].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow8Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_WILLPOWER ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow8Right", L""..GameData.Player.Stats[GameData.Stats.WILLPOWER].currentValue )
end

function EA_Window_Inspection.UpdateOffenseLabels()
    local rightText=L"0"
    local rightData = 0

    if (EA_Window_Inspection.equipmentData[1].dps > 0) then
        rightText = wstring.format(L"%.01f",EA_Window_Inspection.equipmentData[1].dps)
    end
--    LabelSetText( "EA_Window_InspectionStatsWindow1Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_MAIN_HAND ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow1Right", rightText )

    rightText = L"0"
    if (EA_Window_Inspection.equipmentData[2].dps > 0) then
        rightText = wstring.format(L"%.01f",EA_Window_Inspection.equipmentData[2].dps)
    end
--    LabelSetText( "EA_Window_InspectionStatsWindow2Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_OFF_HAND ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow2Right", rightText )

    rightData = (GameData.Player.Stats[7].currentValue/(GameData.Player.level*5+50)*.25)*100.0
    rightText = wstring.format(L"%.01f",rightData)
--    LabelSetText( "EA_Window_InspectionStatsWindow3Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_ARMOR_PENETRATION ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow3Right", rightText )

    rightText = L"0"
    if (EA_Window_Inspection.equipmentData[3].dps > 0) then
        rightText = wstring.format(L"%.01f",EA_Window_Inspection.equipmentData[3].dps)
    end
--    LabelSetText( "EA_Window_InspectionStatsWindow4Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_RANGED ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow4Right", rightText )

    rightData = GameData.Player.Stats[9].currentValue/5
    rightText = wstring.format(L"%d",rightData)
--    LabelSetText( "EA_Window_InspectionStatsWindow5Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_SPELL_BONUS ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow5Right", rightText )

    rightData = GameData.Player.Stats[3].currentValue/5
    rightText = wstring.format(L"%d",rightData)
--    LabelSetText( "EA_Window_InspectionStatsWindow6Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_HEALING_BONUS ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow6Right", rightText )

    rightData = 10
    rightText = wstring.format(L"%d",rightData)
--    LabelSetText( "EA_Window_InspectionStatsWindow7Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_DAMAGE_CRIT_PERCENT ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow7Right", L"N/A" )

    rightData = 10
    rightText = wstring.format(L"%d",rightData)
--    LabelSetText( "EA_Window_InspectionStatsWindow8Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_HEAL_CRIT_PERCENT ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow8Right", L"N/A" )
end

function EA_Window_Inspection.UpdateDefenseLabels()
--    LabelSetText( "EA_Window_InspectionStatsWindow1Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_ARMOR ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow1Right", L""..GameData.Player.armorValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow2Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_CORPOREALRESIST ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow2Right", L""..GameData.Player.Stats[GameData.Stats.CORPOREALRESIST].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow3Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_SPIRITRESIST ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow3Right", L""..GameData.Player.Stats[GameData.Stats.SPIRITRESIST].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow4Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_ELEMENTALRESIST ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow4Right", L""..GameData.Player.Stats[GameData.Stats.ELEMENTALRESIST].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow5Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_BONUS_BLOCK ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow5Right", L""..GameData.Player.Stats[GameData.Stats.BLOCKSKILL].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow6Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_BONUS_PARRY ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow6Right", L""..GameData.Player.Stats[GameData.Stats.PARRYSKILL].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow7Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_BONUS_EVADE ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow7Right", L""..GameData.Player.Stats[GameData.Stats.EVADESKILL].currentValue )
--    LabelSetText( "EA_Window_InspectionStatsWindow8Left", EA_Window_Inspection.AdjustStatLabel(GetString( StringTables.Default.LABEL_BONUS_DISRUPT ))..L":" )
--    LabelSetText( "EA_Window_InspectionStatsWindow8Right", L""..GameData.Player.Stats[GameData.Stats.DISRUPTSKILL].currentValue )
end

function EA_Window_Inspection.AdjustStatLabel(szLabelText)
    if (wstring.len(szLabelText) > 12) then
        szLabelText = wstring.sub(szLabelText, 0, 9)
        szLabelText = szLabelText..L"..."
    end
    return szLabelText
end

function EA_Window_Inspection.UpdateTitleLabel()
    local activeTitle = L""
    if( GameData.Player.activeTitle ~= nil and GameData.Player.activeTitle ~= 0 ) then
        titleData = TomeGetPlayerTitleData(GameData.Player.activeTitle)
        if (titleData ~= nil) and (titleData.name ~= nil) then
            offset = wstring.find(titleData.name, L",")
            if (offset ~= nil) then
                activeTitle = wstring.sub(titleData.name, offset+1)
            else
                activeTitle = titleData.name
            end
            if (activeTitle == L"") or (activeTitle == nil) then
                activeTitle = L""
            end
        end
        EA_Window_Inspection.currentTitleSelection = GameData.Player.activeTitle
    end

    LabelSetText( "EA_Window_InspectionContentsImageTitleLabel", activeTitle )
end

function EA_Window_Inspection.HideCloak()
--	EA_Window_Inspection.hideCloak = ButtonGetPressedFlag("EA_Window_InspectionEquipmentHideCloak")
end

function EA_Window_Inspection.ShowHideCloakOnly()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideCloak", true)
--	EA_Window_Inspection.CreateTooltip("EA_Window_InspectionEquipmentHideCloak", GetString( StringTables.Default.TOOLTIP_SHOW_CLOAK ) )
end

function EA_Window_Inspection.ShowHideCloak()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideCloak", true)
--	EA_Window_Inspection.EquipmentMouseOver()
end

function EA_Window_Inspection.HideHideCloak()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideCloak", false)
end

function EA_Window_Inspection.HideHelm()
--	EA_Window_Inspection.hideHelm = ButtonGetPressedFlag("EA_Window_InspectionEquipmentHideHelm")
end

function EA_Window_Inspection.ShowHideHelmOnly()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideHelm", true)
--	EA_Window_Inspection.CreateTooltip("EA_Window_InspectionEquipmentHideHelm", GetString( StringTables.Default.TOOLTIP_SHOW_HELM ) )
end

function EA_Window_Inspection.ShowHideHelm()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideHelm", true)
--	EA_Window_Inspection.EquipmentMouseOver()
end

function EA_Window_Inspection.HideHideHelm()
--	WindowSetShowing("EA_Window_InspectionEquipmentHideHelm", false)
end

function EA_Window_Inspection.MouseOverDone(index)
    if EA_Window_Inspection.currentStatSelection == 1 then
        return EA_Window_Inspection.MouseOverStatsDone(index)
    elseif EA_Window_Inspection.currentStatSelection == 2 then
        return EA_Window_Inspection.MouseOverOffenseDone(index)
    elseif EA_Window_Inspection.currentStatSelection == 3 then
        return EA_Window_Inspection.MouseOverDefenseDone(index)
    end
end

function EA_Window_Inspection.MouseOverStatsDone(index)
    if (1 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.STRENGTH)
        return true
    elseif (2 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.TOUGHNESS)
        return true
    elseif (3 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.WOUNDS)
        return true
    elseif (4 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.INITIATIVE)
        return true
    elseif (5 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.WEAPONSKILL)
        return true
    elseif (6 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.BALLISTICSKILL)
        return true
    elseif (7 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.INTELLIGENCE)
        return true
    elseif (8 == index) then
        EA_Window_Inspection.OnMouseOverStat(GameData.Stats.WILLPOWER)
        return true
    end

    DEBUG(L"FALSE")	
    return false
end

function EA_Window_Inspection.MouseOverOffenseDone(index)
    if (1 == index) then
        return false
    elseif (2 == index) then
        return false
    elseif (3 == index) then
        return false
    elseif (4 == index) then
        return false
    elseif (5 == index) then
        return false
    elseif (6 == index) then
        return false
    elseif (7 == index) then
        return false
    elseif (8 == index) then
        return false
    end
    
    return false
end

function EA_Window_Inspection.MouseOverDefenseDone(index)
    if (1 == index) then
        EA_Window_Inspection.OnMouseOverArmorValue()
        return true
    elseif (2 == index) then
        return false
    elseif (3 == index) then
        return false
    elseif (4 == index) then
        return false
    elseif (5 == index) then
        return false
    elseif (6 == index) then
        return false
    elseif (7 == index) then
        return false
    elseif (8 == index) then
        return false
    end
    
    return false
end

function EA_Window_Inspection.StatsMouseOver()
    local windowID = WindowGetId(SystemData.ActiveWindow.name)
    if (EA_Window_Inspection.MouseOverDone(windowID)) then
        return
    end
    
    EA_Window_Inspection.CreateTooltip("EA_Window_InspectionContentsStatsWindow"..windowID, EA_Window_Inspection.GetStatsToolTip(windowID), EA_Window_Inspection.GetStatsToolTipLine2(windowID) )
end

function EA_Window_Inspection.GetStatsToolTip(index)
    if EA_Window_Inspection.currentStatSelection == 1 then
        return EA_Window_Inspection.GetStatsLabelsTooltip(index)
    elseif EA_Window_Inspection.currentStatSelection == 2 then
        return EA_Window_Inspection.GetOffenseLabelsTooltip(index)
    elseif EA_Window_Inspection.currentStatSelection == 3 then
        return EA_Window_Inspection.GetDefenseLabelsTooltip(index)
    end
    
    return L""
end

function EA_Window_Inspection.GetStatsToolTipLine2(index)
    if EA_Window_Inspection.currentStatSelection == 1 then
        return EA_Window_Inspection.GetStatsLabelsTooltipLine2(index)
    elseif EA_Window_Inspection.currentStatSelection == 2 then
        return EA_Window_Inspection.GetOffenseLabelsTooltipLine2(index)
    elseif EA_Window_Inspection.currentStatSelection == 3 then
        return EA_Window_Inspection.GetDefenseLabelsTooltipLine2(index)
    end
    
    return L""
end

function EA_Window_Inspection.GetStatsLabelsTooltip(index)
    local retString = L""
    if (1 == index) then
        retString = GetString( StringTables.Default.LABEL_STRENGTH )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.STRENGTH)
        return retString
    elseif (2 == index) then
        retString = GetString( StringTables.Default.LABEL_TOUGHNESS )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.TOUGHNESS)
        return retString
    elseif (3 == index) then
        retString = GetString( StringTables.Default.LABEL_WOUNDS )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.WOUNDS)
        return retString
    elseif (4 == index) then
        retString = GetString( StringTables.Default.LABEL_INITIATIVE )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.INITIATIVE)
        return retString
    elseif (5 == index) then
        retString = GetString( StringTables.Default.LABEL_WEAPONSKILL )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.WEAPONSKILL)
        return retString
    elseif (6 == index) then
        retString = GetString( StringTables.Default.LABEL_BALLISTICSKILL )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.BALLISTICSKILL)
        return retString
    elseif (7 == index) then
        retString = GetString( StringTables.Default.LABEL_INTELLIGENCE )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.INTELLIGENCE)
        return retString
    elseif (8 == index) then
        retString = GetString( StringTables.Default.LABEL_WILLPOWER )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.WILLPOWER)
        return retString
    end
    
    return L""
end

function EA_Window_Inspection.GetOffenseLabelsTooltip(index)
    if (1 == index) then
        return GetString( StringTables.Default.LABEL_MAIN_HAND )
    elseif (2 == index) then
        return GetString( StringTables.Default.LABEL_OFF_HAND )
    elseif (3 == index) then
        return GetString( StringTables.Default.LABEL_ARMOR_PENETRATION )
    elseif (4 == index) then
        return GetString( StringTables.Default.LABEL_RANGED )
    elseif (5 == index) then
        return GetString( StringTables.Default.LABEL_SPELL_BONUS )
    elseif (6 == index) then
        return GetString( StringTables.Default.LABEL_HEALING_BONUS )
    elseif (7 == index) then
        return GetString( StringTables.Default.LABEL_DAMAGE_CRIT_PERCENT )
    elseif (8 == index) then
        return GetString( StringTables.Default.LABEL_HEAL_CRIT_PERCENT )
    end
    
    return L""
end

function EA_Window_Inspection.GetDefenseLabelsTooltip(index)
    local retString = L""
    if (1 == index) then
        retString = GetString( StringTables.Default.LABEL_ARMOR )
        retString = retString..L": "
        retString = retString..GameData.Player.armorValue
        return retString
    elseif (2 == index) then
        retString = GetString( StringTables.Default.LABEL_CORPOREALRESIST )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.CORPOREALRESIST)
        return retString
    elseif (3 == index) then
        retString = GetString( StringTables.Default.LABEL_SPIRITRESIST )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.SPIRITRESIST)
        return retString
    elseif (4 == index) then
        retString = GetString( StringTables.Default.LABEL_ELEMENTALRESIST )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.ELEMENTALRESIST)
        return retString
    elseif (5 == index) then
        retString = GetString( StringTables.Default.LABEL_BONUS_BLOCK )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.BLOCKSKILL)
        return retString
    elseif (6 == index) then
        retString = GetString( StringTables.Default.LABEL_BONUS_PARRY )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.PARRYSKILL)
        return retString
    elseif (7 == index) then
        retString = GetString( StringTables.Default.LABEL_BONUS_EVADE )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.EVADESKILL)
        return retString
    elseif (8 == index) then
        retString = GetString( StringTables.Default.LABEL_BONUS_DISRUPT )
        retString = retString..EA_Window_Inspection.GetBasicStatTooltip(GameData.Stats.DISRUPTSKILL)
        return retString
    end
    
    return L""
end

function EA_Window_Inspection.GetStatsLabelsTooltipLine2(index)
    local retString = L""
    if (1 == index) then
        return
    elseif (2 == index) then
        return
    elseif (3 == index) then
        return
    elseif (4 == index) then
        return
    elseif (5 == index) then
        return
    elseif (6 == index) then
        return
    elseif (7 == index) then
        return
    elseif (8 == index) then
        return
    end
    
    return
end

function EA_Window_Inspection.GetOffenseLabelsTooltipLine2(index)
    if (1 == index) then
        return
    elseif (2 == index) then
        return
    elseif (3 == index) then
        return
    elseif (4 == index) then
        return
    elseif (5 == index) then
        return
    elseif (6 == index) then
        return
    elseif (7 == index) then
        return
    elseif (8 == index) then
        return
    end
    
    return
end

function EA_Window_Inspection.GetDefenseLabelsTooltipLine2(index)
    local retString = L""
    if (1 == index) then
        return
    elseif (2 == index) then
        return GetString( StringTables.Default.TEXT_CORPOREALRESIST_DESC )
    elseif (3 == index) then
        return GetString( StringTables.Default.TEXT_SPIRITRESIST_DESC )
    elseif (4 == index) then
        return GetString( StringTables.Default.TEXT_ELEMENTALRESIST_DESC )
    elseif (5 == index) then
        return
    elseif (6 == index) then
        return
    elseif (7 == index) then
        return
    elseif (8 == index) then
        return
    end
    
    return
end

function EA_Window_Inspection.GetBasicStatTooltip(statID)
    local retString = L""..L": "
    retString = retString..GameData.Player.Stats[statID].currentValue
    retString = retString..L"("
    retString = retString..GameData.Player.Stats[statID].baseValue
    retString = retString..L"+"
    retString = retString..GameData.Player.Stats[statID].currentValue-GameData.Player.Stats[statID].baseValue
    retString = retString..L")"
    return retString
end

function EA_Window_Inspection.PaperDollMouseUp()
    if Cursor.IconOnCursor() and EA_Window_Inspection.dropPending == false then
        EA_Window_Inspection.AutoEquipItem(Cursor.Data.SourceSlot)
    end
end

function EA_Window_Inspection.UpdateStatIcon(wndName, iconNum)
    if (wndName == nil) or (wndName == "") then
        return
    end
    if (iconNum == 0) then
        WindowSetShowing(wndName, false)
        return
    end
    
    local texture, x, y = GetIconData( iconNum ) 
    DynamicImageSetTexture( wndName, texture, x, y )
    WindowSetShowing(wndName, true)
end

function EA_Window_Inspection.UpdateStatIcons()
    local texture, x, y
    -- Stats selections
    if EA_Window_Inspection.currentStatSelection == 1 then
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow1IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.STRENGTH].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow2IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.TOUGHNESS].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow3IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.WOUNDS].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow4IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.INITIATIVE].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow5IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.WEAPONSKILL].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow6IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.BALLISTICSKILL].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow7IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.INTELLIGENCE].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow8IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.WILLPOWER].iconNum )
    -- Offense selections
    elseif EA_Window_Inspection.currentStatSelection == 2 then
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow1IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_MAIN_HAND].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow2IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_OFF_HAND].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow3IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_ARMOR_PENETRATION].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow4IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_RANGED].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow5IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_SPELL_BONUS].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow6IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_HEALING_BONUS].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow7IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_DAMAGE_CRIT_PERCENT].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow8IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_HEAL_CRIT_PERCENT].iconNum )
    -- Defense selections
    elseif EA_Window_Inspection.currentStatSelection == 3 then
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow1IconBase", EA_Window_Inspection.StatIconInfo[StringTables.Default.LABEL_ARMOR].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow2IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.CORPOREALRESIST].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow3IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.SPIRITRESIST].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow4IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.ELEMENTALRESIST].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow5IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.BLOCKSKILL].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow6IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.PARRYSKILL].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow7IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.EVADESKILL].iconNum )
        EA_Window_Inspection.UpdateStatIcon("EA_Window_InspectionContentsStatsWindow8IconBase", EA_Window_Inspection.StatIconInfo[GameData.Stats.DISRUPTSKILL].iconNum )
    end
end

function EA_Window_Inspection.CreateTooltip(wndName, line1, line2)
    Tooltips.CreateTextOnlyTooltip( wndName )  
    Tooltips.SetTooltipText( 1, 1, line1 )
    Tooltips.SetTooltipColorDef( 1, 1, Tooltips.COLOR_HEADING )
    if (line2 ~= nil) then
        Tooltips.SetTooltipText( 2, 1, line2 )  
    end
    Tooltips.Finalize()
    Tooltips.AnchorTooltip( Tooltips.ANCHOR_WINDOW_RIGHT )
end
